package com.zf.shuashua.utils;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.widget.Toast;

public class MyToast {

    protected static Toast toast;

    public static void showToast(final Context context, final int resId) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            public void run() {
                if (toast == null) {
                    toast = Toast.makeText(context, resId, Toast.LENGTH_SHORT);
                } else {
                    toast.setText(resId);
                }
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            }
        });
    }

    public static void showToast(final Context context, final String text) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            public void run() {
                if (toast == null) {
                    toast = Toast.makeText(context, text, Toast.LENGTH_SHORT);
                } else {
                    toast.setText(text);
                }
                toast.setGravity(Gravity.CENTER, 0,0);
                toast.show();
            }
        });
    }
}
